//
//  OneViewController.m
//  DemoTest
//
//  Created by DaShuEdu on 2017/4/25.
//  Copyright © 2017年 DaShuEdu. All rights reserved.
//

#import "OneViewController.h"
#import "FiveViewController.h"
#import "MessageButton.h"
#import "TitleIconButton.h"
#import <Masonry/Masonry.h>

@interface OneViewController ()

@property (nonatomic, strong) CALayer *frameLayer;
@property (nonatomic, strong) UIImageView *imageV;

@end

@implementation OneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
    self.navigationItem.rightBarButtonItem = bar;
    
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(150, 50, 100, 100)];
    [btn setTitle:@"click me" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    MessageButton *messageBtn = [[MessageButton alloc] initWithFrame:CGRectMake(100, 180, 19, 30.5)];
    [messageBtn setImage:[UIImage imageNamed:@"消息"] forState:UIControlStateNormal];
    [messageBtn setTitle:@"消息" forState:UIControlStateNormal];

    [self.view addSubview:messageBtn];
    
    UIView *contentV = [[UIView alloc] initWithFrame:CGRectMake(150, 450, 100, 100)];
    UIImageView *mv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 80, 40)];
    mv.image = [UIImage imageNamed:@"android"];
    [contentV addSubview:mv];
    contentV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:contentV];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAciton)];
    [contentV addGestureRecognizer:tap];
    
    UITextField *tf = [[UITextField alloc] init];
    tf.backgroundColor = [UIColor whiteColor];
    tf.frame = CGRectMake(50, 240, 100, 30);
    tf.keyboardType = UIKeyboardTypeNamePhonePad;
    tf.secureTextEntry = YES;
    [self.view addSubview:tf];
    
    TitleIconButton *iconButton = [[TitleIconButton alloc] init];
    iconButton.frame = CGRectMake(50, 300, 65, 20);
    [iconButton setImage:[UIImage imageNamed:@"wechat"] forState:UIControlStateNormal];
    [iconButton setTitle:@"微信" forState:UIControlStateNormal];
    [self.view addSubview:iconButton];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(200, 300, 100, 100)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 11, 6)];
    self.imageV.image = [UIImage imageNamed:@"向下黑"];
    [view addSubview:self.imageV];
    
    UIButton *selectButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 21, 26)];
    [selectButton addTarget:self action:@selector(selectAction:) forControlEvents:UIControlEventTouchUpInside];
    selectButton.selected = NO;
    [view addSubview:selectButton];
    
    UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 100, 150, 100)];
    infoLabel.backgroundColor = [UIColor whiteColor];
    infoLabel.numberOfLines = 4;
    NSString *totalStr = @"LRU: 缓存支持淘汰算法缓存控制支持多种缓存控制方法：总数量、总大小、存活时间、空闲空间兼容性: API 基本和 NSCache 保持一致, 所有方法都是线程安全的内存缓存对象释放控制: 对象的释放(release) 可以配置为同步或异步进行，可以配置在主线程或后台线程进行自动清空: 当收到内存警告或 App 进入后台时，缓存可以配置为自动清空磁盘缓存可定制性: 磁盘缓存支持自定义的归档解档方法，以支持那些没有实现 NSCoding 协议的对象存储类型控制: 磁盘缓存支持对每个对象的存储类型 (SQLite/文件) 进行自动或手动控制，以获得更高的存取性能。阅读全文";
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:totalStr];
    NSRange range = NSMakeRange(totalStr.length-4, 4);
    [attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    style.lineBreakMode = NSLineBreakByTruncatingMiddle;
    [attri addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, totalStr.length)];
    infoLabel.attributedText = attri;
    [self.view addSubview:infoLabel];
}

- (void)selectAction:(UIButton *)sender {
    if (sender.selected) {
        [UIView animateWithDuration:0.5 animations:^{
            self.imageV.transform = CGAffineTransformRotate(self.imageV.transform, M_PI);
        } completion:^(BOOL finished) {
            self.imageV.transform = CGAffineTransformIdentity;
            self.imageV.image = [UIImage imageNamed:@"向下黑"];
            sender.selected = NO;
        }];
    } else {
        [UIView animateWithDuration:0.5 animations:^{
            self.imageV.transform = CGAffineTransformRotate(self.imageV.transform, M_PI);
        } completion:^(BOOL finished) {
            self.imageV.transform = CGAffineTransformIdentity;
            self.imageV.image = [UIImage imageNamed:@"向上黄"];
            sender.selected = YES;
        }];
    }
}

- (void)tapAciton {
    NSLog(@"tap");
}

- (void)dismiss {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)change:(UIButton *)sender {
    FiveViewController *five = [[FiveViewController alloc] init];
    [self.navigationController pushViewController:five animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
